package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.view.View;
import android.widget.ImageView;
import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemGuideUserShowBinding;
import com.jwdf.uda.ui.activity.PhotoActivity;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.GuideDetailItem;
import com.jwdf.uda.utils.StringUtils;
import com.jwdf.uda.view.GridImageLayout;
import java.util.ArrayList;

/**
 * 类说明：
 */
public class GuideUserShowViewHolder extends AbsViewHolder<GuideDetailItem> {
    private ItemGuideUserShowBinding mItemBinding;

    public GuideUserShowViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
    }

    @Override
    protected void onBindView(GuideDetailItem item) {
        final PbBean.PbHomeRecommend userShow = item.userShow;
        if (userShow == null) return;
        String styleTag = null;
//        if (userShow.getStyleTagListCount() > 0) {
//            styleTag = StringUtils.filterNullAndTrim(userShow.getStyleTagList(0));
//        }

        PbBean.PbUserSimple userInfo = userShow.getUserInfo();
        String nickName = StringUtils.isNullEmpty(styleTag) ? StringUtils.filterNullAndTrim(userInfo.getNickname()) : convertView.getContext().getString(R.string.garb_add_stylename, StringUtils.filterNullAndTrim(userInfo.getNickname()), styleTag);
        mItemBinding.tvName.setText(convertView.getContext().getString(R.string.guide_detail_usershow, nickName));
        mItemBinding.tvName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (userShow != null) {
                    UserInfoActivity.start(v.getContext(), userShow.getUserInfo().getUserId(), userShow.getUserInfo().getIsDesigner());
                }
                return;
            }
        });

//        final List<PbBean.PbImage> images = userShow.getImageListList();
        final ArrayList<String> urls = new ArrayList<>();
//        for (PbBean.PbImage image : images) {
//            urls.add(image.getUrl());
//        }
        mItemBinding.gridimageLayout.setImage(urls);
        mItemBinding.gridimageLayout.setOnImageItemClickListener(new GridImageLayout.OnImageItemClickListener() {
            @Override
            public void onImageClick(int index, ImageView imageView) {
                PhotoActivity.start(imageView.getContext(), urls, index);
            }
        });
    }
}
